/*
 * Copyright 2010 Kevin L'Huillier <klhuillier@gmail.com>
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package org.lhuillier.pwsafe.model;


public enum HeaderFieldType {
    VERSION(0x00),
    UUID(0x01),
    PREFS(0x02),
    TREE_DISPLAY(0x03),
    SAVE_TIME(0x04),
    SAVE_PERSON(0x05),
    SAVE_APP(0x06),
    SAVE_USER(0x07),
    SAVE_HOST(0x08),
    DB_NAME(0x09),
    DB_DESC(0x0a),
    END_OF_HEADER(0xff);

    private final byte typeId;

    HeaderFieldType(int typeId) {
        this.typeId = (byte) typeId;
    }

    public byte getTypeId() {
        return typeId;
    }

    public static HeaderFieldType forTypeId(byte typeId) {
        if (typeId < 0) {
            return forTypeId(256 + (typeId & 0x7f));
        } else {
            return forTypeId((int) typeId);
        }
    }

    public static HeaderFieldType forTypeId(int typeId) {
        for (HeaderFieldType type : values()) {
            if (type.typeId == typeId) {
                return type;
            }
        }
        return null;
    }
}
